package com.zhaolixiang.slidetabview

import android.app.Activity
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.ViewTreeObserver
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    private var count=13;
    private lateinit var activity:Activity
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        activity=this
        for(i in 0 until count){
            addView(i)
        }

        ll_zong.viewTreeObserver.addOnGlobalLayoutListener(object: ViewTreeObserver.OnGlobalLayoutListener {
            override fun onGlobalLayout() {
                ll_zong.viewTreeObserver.removeOnGlobalLayoutListener(this)
                val width=ll_zong.getChildAt(0).width+
                        ll_zong.getChildAt(1).width+
                        ll_zong.getChildAt(2).width+
                        ll_zong.getChildAt(3).width
                for (i in 0 until count){
                    Log.e("每个控件宽短",ll_zong.getChildAt(i).width.toString())
                }
                //437
                //875
               // mHorizontalScrollView.smoothScrollBy(width,0)
                mHorizontalScrollView.setMinWidth(width)
            }

        })
        bt_add.setOnClickListener{
            val tv=TextView(activity)
            tv.text="我是文本"+(8)
            tv.textSize=36f
            ll_zong.addView(tv,0)
        }
    }

    fun addView( i:Int){
        when(i%4){
            0->{
                val tv=TextView(activity)
                tv.text="证券基金"
                tv.textSize=36f
                ll_zong.addView(tv)
            }
            1->{
                val tv=TextView(activity)
                tv.text="股权基金"
                tv.textSize=36f
                ll_zong.addView(tv)
            }
            2->{
                val tv=TextView(activity)
                tv.text="非标基金"
                tv.textSize=36f
                ll_zong.addView(tv)
            }
            3->{
                val tv=TextView(activity)
                tv.text="资金需求"
                tv.textSize=36f
                ll_zong.addView(tv)
            }
        }


    }
}
